﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TS.DataAccess;
using TS.Entities;
using TS.Commons;
using System.Data.SqlClient;
using System.Collections.ObjectModel;

namespace TS.Bussiness
{
    public class GroupBussiness
    {
        /// <summary>
        /// Author: VuongPT
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Collection<Group> GetAllGroup()
        {
            GroupDataAccess grpDao = new GroupDataAccess();
            try
            {
                Collection<Group> grlList = new Collection<Group>();
                grlList = grpDao.GetAllGroup();
                return grlList != null ? grlList : null;
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strFilter"></param>
        /// <param name="strOrderBy"></param>
        /// <param name="totalRecord"></param>
        /// <returns></returns>
        public Collection<Group> ReadGroupPaged(int pageSize, int pageIndex, string strFilter, string strOrderBy, out int totalRecord)
        {
            totalRecord = 0;
            var dataAccess = new GroupDataAccess();
            try
            {
                if (pageIndex >= 0 && pageSize > 0)
                {
                    var result = dataAccess.ReadGroupPaged(pageSize, pageIndex, strFilter, strOrderBy, out totalRecord);
                    if (result != null)
                    {
                        return result;
                    }
                    return null;
                }
                return null;
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return null;
        }
    }
}
